using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioManager : MonoBehaviour
{

    // 设置单例模式
    public static AudioManager Instance {get; private set;}

    // 属性赋值音效，面板拖拽,利用单例模式直接调用对应的方法，即可播放相应的音效
    public AudioClip birdCollision;
    public AudioClip birdSelect;
    public AudioClip birdFlying;
    public AudioClip[] pigCollisions;
    public AudioClip woodCollision;
    public AudioClip woodDestory;

    public void Awake()
    {
        Instance = this;
    }

    public void PlayBirdCollision(Vector3 position)
    {
        AudioSource
        .PlayClipAtPoint(birdCollision, position, 1f);
    }
    
    public void PlayBirdSelect(Vector3 position)
    {
        AudioSource
        .PlayClipAtPoint(birdSelect, position, 1f);
    }
    public void PlayBirdFlying(Vector3 position)
    {
        AudioSource
        .PlayClipAtPoint(birdFlying, position, 1f);
    }
    public void PlayPigCollision(Vector3 position)
    {
        // 取得随机音效，播放随机音效
        int randomIndex = Random.Range(0, pigCollisions.Length);
        AudioClip ac = pigCollisions[randomIndex];
        AudioSource
        .PlayClipAtPoint(birdFlying, position, 1f);
    }
    public void PlayWoodCollision(Vector3 position)
    {
        AudioSource
        .PlayClipAtPoint(woodCollision, position, .6f);
    }
    public void PlayWoodDestory(Vector3 position)
    {
        AudioSource
        .PlayClipAtPoint(woodDestory, position, .5f);
    }
}
